<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>茂职院后台登录系统</title>
    <link rel="stylesheet" href="__ADMIN__/frame/layui/css/layui.css">
    <link rel="stylesheet" href="__ADMIN__/frame/static/css/style.css">
    <link rel="icon" href="__ADMIN__/frame/static/image/code.png">
</head>

<body class="login-body body">
    <div class="login-box">
        <form class="layui-form layui-form-pane" method="get" action="">
            <div class="layui-form-item">
                <h3>茂职院报修总后台</h3>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">账号：</label>
                <div class="layui-input-inline">
                    <input type="text" name="username" class="layui-input" lay-verify="account" placeholder="账号" autocomplete="on" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">密码：</label>
                <div class="layui-input-inline">
                    <input type="password" name="password" class="layui-input" lay-verify="password" placeholder="密码" maxlength="20" />
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">验证码：</label>
                <div class="layui-input-inline">
                    <input type="number" name="code" id="code" class="layui-input" lay-verify="code" placeholder="验证码" maxlength="4" /><img
                onclick="this.src='{:url('Login/captche')}?'+new Date().getTime();"  src="{:url('Login/captche')}" id="codePic" alt="点击更换">
            </div>
                </div>
                <div class="layui-form-item">
                    <button type="reset" class="layui-btn layui-btn-danger btn-reset">重置</button>
                    <button type="button" class="layui-btn btn-submit" lay-submit="" lay-filter="sub">立即登录</button>
                </div>
        </form>
    </div>
    <script type="text/javascript" src="__ADMIN__/frame/layui/layui.js"></script>
    <script type="text/javascript">
    layui.use(['form', 'layer'], function() {

        // 操作对象
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery;

        // 验证
        form.verify({
            account: function(value) {
                if (value == "") {
                    return "请输入用户名";
                }
            },
            password: function(value) {
                if (value == "") {
                    return "请输入密码";
                }
            },
            code: function(value) {
                if (value == "") {
                    return "请输入验证码";
                }
            }
        });

        // 提交监听
        form.on('submit(sub)', function(data) {
            $.ajax({
                type: 'post',
                url: "{:url('Login/login')}",
                data: data.field,
                dataType: 'json',
                success: function(data) {
                    console.log(data)
                    if (data.status == 0) {
                        // layer.msg(data.msg, {
                        //   icon: 1,
                        //   time: 1000 //2秒关闭（如果不配置，默认是3秒）
                        // }, function(){
                        $(window).attr('location', "{:url('Index/index')}");
                        // });
                    } else {
                        layer.msg(data.msg, { icon: 5, time: 1000 }, function() {
                            $("#codePic").attr("src", "{:url('Login/captche')}?flag=" + Math.random());
                            $('#code').val('');
                        });
                    }
                },
                error: function(data) {
                    layer.msg('提交失败!', { icon: 5, time: 1000 });
                },
            });
            return false;
        });
    })
    </script>
</body>

</html>